package com.vcc.core.model;

import lombok.Data;


@Data
public class Result<T> {
    private int code;

    private String message;

    private T data;

    private Result(T data) {
        this.code = 200;
        this.data = data;
    }

    private Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static <T> Result<T> returnDefault() {
        return returnGenEriCity(null);
    }

    public static Result<Boolean> returnDefaultTrue() {
        return returnGenEriCity(true);
    }

    public static Result<Boolean> returnDefaultFalse() {
        return returnGenEriCity(false);
    }

    public static <T> Result<T> returnGenEriCity(T t) {
        return returnGenEriCity(StatusEnum.SUCCESS, t);
    }

    public static <T> Result<T> returnGenEriCity(StatusEnum codeEnum) {
        return returnGenEriCity(codeEnum, null);
    }

    public static <T> Result<T> returnGenEriCity(StatusEnum codeEnum, T t) {
        return codeEnum == null ? new Result<T>(t) : new Result<T>(codeEnum.getStatus(), codeEnum.getMessage(), t);
    }

    public static <T> Result<T> returnError(int code, String message, T data) {
        return new Result<T>(code, message, data);
    }

    public static <T> Result<T> returnError(int code, String message) {
        return new Result<T>(code, message);
    }

}
